﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace Tornado
{
    public partial class frmLazer : Form
    {
        [DllImport("user32.dll")]
        public static extern int GetCursorPos(ref Point lpPoint);

        const int minD = 20;

        public frmLazer()
        {
            InitializeComponent();
        }

        private void tmrFollowMouse_Tick(object sender, EventArgs e)
        {
              setPostion();
        }
        public void setPostion()
        {
            Point mousePos = new Point(0,0);
            GetCursorPos(ref mousePos);
            this.Top = mousePos.Y-this.Width/2;
            this.Left = mousePos.X-this.Height/2;
        }

        private void frmLazer_Load(object sender, EventArgs e)
        {
            this.Width = 20;
            this.Height = 20;
            tmrFollowMouse.Enabled = true;
            Cursor.Hide();
        }

        private void frmLazer_MouseClick(object sender, MouseEventArgs e)
        {

            switch (e.Button)
            {
                case MouseButtons.Middle:
                    Application.Exit();

                    break;
                case MouseButtons.Left:
                    changeSize(5);
                    break;
                case MouseButtons.Right:
                    changeSize(-5);
                    break;
            }
        }
        private void changeSize(int ratio)
        {
            if (Math.Abs(this.Width + ratio) >= minD)
            {
                this.Width += ratio;
                this.Height += ratio;
            }
        }

        private void frmLazer_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Middle)
            {
                Application.Exit();
            }
        }

        private void frmLazer_FormClosing(object sender, FormClosingEventArgs e)
        {
            Cursor.Show();
        }
    }
}
